<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* @framework : Codeigniter Framework
*
* @author: fatangel26
*
*/

	class User_model extends CI_Model
	{
        protected $_table;

		public function __construct()
		{
			parent::__construct();

            $this->load->database();

            $this->_table = 'tbl_admin';
		}

        /*Basic Method*/

        public function select($data = array())
        {
            if(empty($data))
            {
                $query = $this->db->get($this->_table);

                if($query->num_rows()>0)
                    return $query->result_object();
            }
            else
            {
                if(isset($data['admin_id']))
                {
                    $query = $this->db->from($this->_table)
                                      ->where($data)
                                      ->get();

                    if($query->num_rows()>0)
                        return $query->row();
                }
            }

            return FALSE;
        }

        public function edit($user_id,$data = array())
        {
            $query = $this->db->update($this->_table,$data,array('admin_id' => $user_id));

            if($query)
                return TRUE;
            return FALSE;
        }

        public function create($data = array())
        {
            $query = $this->db->insert($this->_table,$data);

            if($this->db->affected_rows()==1)
                return TRUE;
            return FALSE;
        }

        public function delete($user_id)
        {
            $query = $this->db->delete($this->_table, array('admin_id' => $user_id));

            if($this->db->affected_rows())
                return TRUE;
            return FALSE;
        }

        /*Magic Method*/
        public function checkLoginAdmin($u,$p,$e)
        {
            $condition = array(
                'admin_username'    => $u,
                'admin_password'    => md5($p),
                'admin_email'       => $e
            );

            $query = $this->db->get_where($this->_table,$condition);

            if($query->num_rows()==1)
                return $query->row();
            return FALSE;
        }


	}

/* End of file User_model.php */
/* Location: ./models/backend/user_model.php */